<!--
 * @Author: xiaodong 565071984@qq.com
 * @Date: 2022-05-08 20:56:20
 * @LastEditors: xiaodong 565071984@qq.com
 * @LastEditTime: 2022-05-08 22:12:52
 * @FilePath: /小票/src/views/orderManagement/roleManagement/components/UserManagementEdit.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogFormVisible"
    width="600px"
    @close="close"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-form-item :label="$t('install.version') /*版本号*/" prop="version">
        <el-input v-model="form.version"></el-input>
      </el-form-item>

      <el-form-item
        :label="$t('install.versionName') /*版本名称*/"
        prop="ver_name"
      >
        <el-input v-model="form.ver_name"></el-input>
      </el-form-item>
      <el-form-item
        :label="$t('install.applicationName') /*应用名称*/"
        prop="name"
      >
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item
        :label="$t('install.forceUpdate') /*强制更新*/"
        prop="is_force"
      >
        <el-radio-group v-model="form.is_force">
          <el-radio :label="0">{{ $t('install.no') /*否*/ }}</el-radio>
          <el-radio :label="1">{{ $t('install.yes') /*是*/ }}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item
        :label="$t('install.packageSize') /*安装包大小*/"
        prop="pkg_size"
      >
        <el-input v-model="form.pkg_size"></el-input>
      </el-form-item>
      <el-form-item :label="$t('install.downLink') /*下载链接*/" prop="pkg_url">
        <el-input v-model="form.pkg_url" type="textarea"></el-input>
      </el-form-item>
      <el-form-item
        :label="$t('install.updateDes') /*更新描述*/"
        prop="pkg_mark"
      >
        <el-input v-model="form.pkg_mark" type="textarea"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <!-- <el-button @click="close">取 消</el-button> -->
      <el-button type="primary" @click="save">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { doEdit } from '@/api/roleManagement'
  import { addPackage, editPackage } from '@/api/business.js'
  export default {
    name: 'RoleManagementEdit',
    data() {
      return {
        form: {
          id: '',
          is_force: 0,
        },
        rules: {
          permission: [
            { required: true, trigger: 'blur', message: '请输入权限码' },
          ],
        },
        title: '',
        dialogFormVisible: false,
      }
    },
    created() {},
    methods: {
      showEdit(row) {
        if (!row) {
          this.title = '添加'
        } else {
          this.title = '修改'
          this.form = Object.assign({}, row)
        }
        this.dialogFormVisible = true
      },
      close() {
        this.$refs['form'].resetFields()
        this.form = this.$options.data().form
        this.dialogFormVisible = false
      },
      save() {
        console.log(this.form.is_force)
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            this.form.is_force = String(this.form.is_force)
            if (this.form.pkg_id) {
              const { msg } = await editPackage(this.form)
              this.$baseMessage(msg, 'success')
              this.$emit('fetch-data')
              this.close()
            } else {
              const { msg } = await addPackage(this.form)
              this.$baseMessage(msg, 'success')
              this.$emit('fetch-data')
              this.close()
            }
          } else {
            return false
          }
        })
      },
    },
  }
</script>
